import store from '@/store/index.js'
let baseUrl = '192.168.101.3'
let baseHeader = {
	"Content-Type": "application/json",
	"Content-Type": "application/x-www-form-urlencoded"
}
let interfaceBaseUrl = `http://${baseUrl}:3000/api`

let tui = {
	request(url, data, method, header) {
		return new Promise((res, rej) => {
			uni.showLoading({
				title: '加载中...',
				mask: false
			});
			// console.log(store.state.user.token);
			uni.request({
				url: interfaceBaseUrl + url,
				method: method || 'GET',
				data: data || {},
				header: {
					'Content-Type': "application/json",
					'token': store.state.user.token
				},
				success: async (result) => {
					let {
						data
					} = result
					// console.log(result);
					if (data.code == 0) {
						res(data.data)
					} else {
						uni.showToast({
							title: '请求失败',
							duration: 2000,
							icon: 'none'
						});
						setTimeout(() => {
							uni.hideLoading()
						}, 2000)
					}
				},
				fail: (err) => {
					console.log(err);
				},
				complete: () => {
					uni.hideLoading()
				}
			});
		})

	}
}

export default tui
